
const state = {
	userAddressList: [],
	tradeInfo:{},
	orderNo: ''
}
const mutations = {
	RECEIVE_TRADEINFO(state,tradeInfo){
		state.tradeInfo = tradeInfo
	},
	RECEIVE_USERADDRESSLIST(state, userAddressList) {
		state.userAddressList = userAddressList
	},

	SET_ORDERNO(state, orderNo) {
		state.orderNo = orderNo
	}
}
const actions = {
	async getTradeInfo({commit}){
		const result = await this.$API.pay.reqTradeInfo()
		if(result.code === 200){
			commit('RECEIVE_TRADEINFO',result.data)
		}
	},
	// 用户地址列表
	async getUserAddressList({ commit }) {
		const result = await this.$API.pay.reqUserAddressList()
		if (result.code === 200) {
			commit('RECEIVE_USERADDRESSLIST', result.data)
			return 'ok'
		}

	},

	// 请求提交创建订单
	async reqSubmitOrder({ commit }, { tradeNo, addressInfo }) {
		const result = await this.$API.pay.reqSubmitOrder(tradeNo, addressInfo)
		if (result.code === 200) {
			console.log(result)
			commit('SET_ORDERNO', result.data)

		}
	}


}
const getters = {


}

export default {
	state,
	mutations,
	actions,
	getters
}
